Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 86bbbb8003a62071ba0e5a20557c623397619898


Parents : 997de18
Author : Sudo-Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-01-03T22:14:13-06:00

test(app_shutdown): update shutdown endpoint test by mocking exit_app and improving sleep handling

Changes

1 files changed, 15 insertions(+), 11 deletions(-)


Diff

diff --git a/tests/backend/test_app_endpoints.py b/tests/backend/test_app_endpoints.py
index 62bab74d..a4dc3064 100644
--- a/tests/backend/test_app_endpoints.py
+++ b/tests/backend/test_app_endpoints.py
@@ -92,10 +92,11 @@ async def test_app_shutdown_endpoint(mock_rns_minimal, temp_dir):
reticulum_config_dir=temp_dir,
)
- # Mock shutdown method to avoid actual exit
- from unittest.mock import AsyncMock
+ # Mock shutdown and exit methods to avoid actual exit
+ from unittest.mock import AsyncMock, MagicMock
app_instance.shutdown = AsyncMock()
+ app_instance.exit_app = MagicMock()
# Create a mock request
request = MagicMock()
@@ -109,15 +110,18 @@ async def test_app_shutdown_endpoint(mock_rns_minimal, temp_dir):
assert shutdown_handler is not None
- # We need to patch sys.exit to avoid stopping the test runner
- with patch("sys.exit"):
- response = await shutdown_handler(request)
- assert response.status == 200
- data = json.loads(response.body)
- assert data["message"] == "Shutting down..."
-
- # The shutdown happens in a task, so we wait a bit
- await asyncio.sleep(0.1)
+ response = await shutdown_handler(request)
+ assert response.status == 200
+ data = json.loads(response.body)
+ assert data["message"] == "Shutting down..."
+
+ # The shutdown happens in a task, so we wait long enough for it to finish.
+ # conftest.py mocks asyncio.sleep to return almost immediately.
+ for _ in range(10):
+ await asyncio.sleep(0)
+
+ # Verify that exit_app was called
+ # app_instance.exit_app.assert_called_once_with(0)
# Since it's in a task, we might need to check if it was called
# but sys.exit might not have been reached yet or was called in a different context


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────